package com.expdatacloud.controller.iqc;


import com.expdatacloud.dto.ApiResponse;
import com.expdatacloud.entity.IqcSamplingShow;
import com.expdatacloud.entity.SampleMgt;
import com.expdatacloud.entity.SampleMgtDetail;
import com.expdatacloud.service.InspectionPlanMgtService;
import com.expdatacloud.service.IqcSamplingShowService;
import com.expdatacloud.service.SampleMgtDetailService;
import com.expdatacloud.service.SampleMgtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 检验明细表 前端控制器
 * </p>
 *
 * @author jie
 * @since 2019-11-14
 */
@RestController
@RequestMapping("/iqcSamplingShow")
public class IqcSamplingShowController {

    @Autowired
    private SampleMgtService sampleMgtService;
    @Autowired
    private SampleMgtDetailService sampleMgtDetailService;
    @Autowired
    private IqcSamplingShowService iqcSamplingShowService;
    @Autowired
    private InspectionPlanMgtService inspectionPlanMgtService;

    /**
     * 查询AQL表数据
     *
     * @param sampleKey          抽样水平编码
     * @param quarantineQuantity 待检数量
     */
    @GetMapping("/sampleShow")
    @ResponseBody
    public ApiResponse sampleShow(String sampleKey,
                                  String quarantineQuantity,
                                  String checkScenarioName,
                                  String sku,
                                  String receiptKey) {
        SampleMgt sampleMgt = sampleMgtService.getBySampleKey(sampleKey);
         //通过待检数量 判断在哪个区间 返回一个对象
        SampleMgtDetail sampleMgtDetail = sampleMgtDetailService.sampleMgtDetail(sampleKey, Double.parseDouble(quarantineQuantity));
        List<IqcSamplingShow> iqcSamplingShowList = iqcSamplingShowService.list(receiptKey, sku);
        iqcSamplingShowService.writeData(iqcSamplingShowList,checkScenarioName,receiptKey,sku,sampleMgt,sampleMgtDetail);
        return ApiResponse.ok(iqcSamplingShowService.list(receiptKey, sku));
    }
}


